package edu.nf.exam.dao.impl;

import edu.nf.exam.dao.ExamPaperInfoDao;
import edu.nf.exam.entity.ExamPaperInfo;
import edu.nf.exam.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Author : QYM
 * @create 2021/6/17
 * 试卷信息表--接口实现类
 */
public class ExamPaperInfoDaoImpl implements ExamPaperInfoDao {
    /**
     * 添加试卷信息
     * @param examPaperInfo
     * @return
     */
    @Override
    public int addExamPaper(ExamPaperInfo examPaperInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        int r = sqlSession.getMapper(ExamPaperInfoDao.class).addExamPaper(examPaperInfo);
        sqlSession.close();
        return r;
    }

    /**
     * 修改试卷信息
     * @param examPaperInfo
     * @return
     */
    @Override
    public int updateExamPaper(ExamPaperInfo examPaperInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        int r = sqlSession.getMapper(ExamPaperInfoDao.class).updateExamPaper(examPaperInfo);
        sqlSession.close();
        return r;
    }

    /**
     * 分页查询
     * @param examPaperName
     * @param paperType
     * @param levelName
     * @param subjectName
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<ExamPaperInfo> queryByTerm(String examPaperName,Integer paperType, String levelName, String subjectName, Integer pageNum, Integer pageSize) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<ExamPaperInfo> list = sqlSession.getMapper(ExamPaperInfoDao.class).queryByTerm(examPaperName,paperType, levelName, subjectName, pageNum, pageSize);
        sqlSession.close();
        return list;
    }

    /**
     * 根据ID查询
     * @param examPaperId
     * @return
     */
    @Override
    public ExamPaperInfo queryExamPaperById(Integer examPaperId) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        ExamPaperInfo exam = sqlSession.getMapper(ExamPaperInfoDao.class).queryExamPaperById(examPaperId);
        sqlSession.close();
        return exam;
    }

    /**
     * 多条件查询
     * @param examPaperInfo
     * @return
     */
    @Override
    public List<ExamPaperInfo> select(ExamPaperInfo examPaperInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<ExamPaperInfo> list = sqlSession.getMapper(ExamPaperInfoDao.class).select(examPaperInfo);
        sqlSession.close();
        return list;
    }
}
